package exercises.Charpter7;

import static net.mindview.util.Print.*;

class DisposeComponent1{
	DisposeComponent1(){
		print("DisposeComponent1 constructed!");
	}
	void dispose(){
		print("DisposeComponent1 Disposed");
	}
}

class DisposeComponent2{
	DisposeComponent2(){
		print("DisposeComponent2 constructed!");
	}
	void dispose(){
		print("DisposeComponent2 Disposed");
	}
}

class DisposeComponent3{
	DisposeComponent3(){
		print("DisposeComponent3 constructed!");
	}
	void dispose(){
		print("DisposeComponent3 Disposed");
	}
}

class Disposeroot{
	DisposeComponent1 a;
	DisposeComponent2 b;
	DisposeComponent3 c; 
	Disposeroot(){
		a = new DisposeComponent1();
		b = new DisposeComponent2();
		c = new DisposeComponent3();
		print("Disposeroot constructed!");
	}
	void dispose(){
		print("Disposeroot Disposed");
		a.dispose();
		b.dispose();
		c.dispose();
	}
}

class DisposeStem extends Disposeroot{
	DisposeStem(){
		print("DisposeStem constructed!");
	}
	void dispose(){
		print("DisposeStem Disposed");
		super.dispose();
	}
}

public class Twelve {
	public static void main(String[] args){
		DisposeStem test = null;
		try{
			test = new DisposeStem();
		} finally{
			test.dispose();
		}
	}
}
